package org.example.sdpback.sdk.exception;

import lombok.extern.slf4j.Slf4j;
import org.example.sdpback.sdk.response.SdpResponseData;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * @className: GlobalExceptionHandler
 * @author: zxy
 * @date: 2024/11/3 15:24
 * @Version: 1.0
 * @description: 全局异常处理器
 **/
@Slf4j
@RestControllerAdvice
public class GlobalExceptionHandler {
    @ExceptionHandler(Exception.class)
    public SdpResponseData<Object> handlerException(Exception e) {
        e.printStackTrace();
        return SdpResponseData.fail(StringUtils.hasText(e.getMessage()) ? e.getMessage() : "请求失败！");
    }
}
